package com.ksyun.campus.dataserver.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 全局统一响应实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseResult<T> {
    private String msg; // 返回信息，成功为success
    private Integer code; // 返回响应状态码，成功为200
    private T data; // 返回数据对象

    private static final String SUCCESS_MSG = "success";
    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = 555;

    // 成功响应
    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(SUCCESS_MSG, SUCCESS_CODE, data);
    }

    // 失败响应
    public static <T> BaseResult<T> error(String msg) {
        return new BaseResult<>(msg, ERROR_CODE, null);
    }
}
